package com.umakr.ax.core.aspect;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

/**
 * 获取数据源
 * @author gx
 */
public class ChooseDataSource extends AbstractRoutingDataSource {
	protected static final Map<String, List<String>> methodType = new HashMap<>();

	/**获取数据源名称*/
	@Override
    protected Object determineCurrentLookupKey() {
		return HandleDataSource.getDataSource();
	}

	/**设置方法名前缀对应的数据源*/
	public void setMethodType(Map<String, String> map) {
		for (Map.Entry<String,String> entry : map.entrySet()) {
			List<String> v = new ArrayList<>();
			String[] types = entry.getKey().split(",");
			for (String type : types) {
				if (StringUtils.isNotBlank(type)) {
					v.add(type);
				}
			}
			methodType.put(entry.getKey(), v);
		}
	}
}
